//
// Created by wenyaxi on 24-10-28.
//
#include "ListNode.h"
#include "common.h"
using namespace std;

class Solution {
public:
    ListNode *reverseList(ListNode *head) {
        if (head == NULL) {
            return NULL;
        }
        ListNode *pre = nullptr;
        ListNode *cur = head;
        ListNode *then = nullptr;
        for (;;) {
            //准备then
            then = cur->next;
            cur->next = pre;
            if (then == nullptr) {
                return cur;
            }
            //准备下次的pre，cur
            pre = cur;
            cur = then;
        }
    }
};

int main(int argc, char *argv[]) {
    auto s = make_unique<Solution>();
    vector<int> a{1};
    ListNode *res = s->reverseList(ListNode::of(a));
    return 0;
}
